<div class="row">
  <div class="col-md-12"
       data-ng-controller="GnSearchController">
    <div class="panel panel-default"
         data-ng-controller="GnAdminToolsSearchController">
      <div class="panel-heading" data-translate="">chooseRecordsToUpdate</div>
      <!-- Add criteria - this should be in a custom search form directive ? -->
      <div class="panel-body">

        <form data-ng-search-form=""
              data-runSearch="false">
              <input type="hidden" name="_csrf" value="{{csrf}}"/>

          <div class="row">
            <div class="col-md-6">
              <div class="form-group">
                <label class="checkbox-inline">
                  <input type="checkbox" data-ng-change="setTemplate(params)"
                         data-ng-model="batchSearchTemplateN" id="batchSearchTemplateN"/>
                  <span data-translate="">METADATA</span>
                </label>
                <label class="checkbox-inline">
                  <input type="checkbox" data-ng-change="setTemplate(params)"
                         data-ng-model="batchSearchTemplateY" id="batchSearchTemplateY"/>
                  <span data-translate="">TEMPLATE</span>
                </label>
                <label class="checkbox-inline">
                  <input type="checkbox" data-ng-change="setTemplate(params)"
                         data-ng-model="batchSearchTemplateS" id="batchSearchTemplateS"/>
                  <span data-translate="">SUB_TEMPLATE</span>
                </label>
              </div>

              <div class="input-group gn-form-any">
                <input type="text"
                       class="form-control"
                       id="gn-any-field"
                       data-ng-model="searchObj.params.any"
                       data-ng-model-options="modelOptions"
                       placeholder="{{'anyPlaceHolder' | translate}}"
                       data-typeahead="address for address in getAnySuggestions($viewValue)"
                       data-typeahead-loading="anyLoading" class="form-control"
                       data-typeahead-min-length="1">

                <div class="input-group-btn">
                  <button type="button"
                          data-ng-click="triggerSearch()"
                          class="btn btn-primary">
                    &nbsp;&nbsp;
                    <i class="fa fa-search"></i>
                    &nbsp;&nbsp;
                  </button>

                  <button type="button"
                          data-ng-click="resetSearch();"
                          title="{{'ClearTitle' | translate}}"
                          class="btn btn-link">
                    <i class="fa fa-times"></i>
                  </button>
                </div>

              </div>
            </div>
            <div class="col-md-6">


              <fieldset class="form-horizontal">
                <div class="form-group">
                  <label data-translate="" class="col-md-4 control-label">_groupOwner</label>
                  <div class="col-md-8">
                    <select class="form-control" id="gn-batchSearchGroupOwner"
                            data-ng-model="searchObj.params.group">
                      <option></option>
                      <option data-ng-repeat="g in batchSearchGroups | orderBy:'name' " value="{{g.id}}"
                      >{{g.label[lang]|empty:g.name}}
                      </option>
                    </select>
                  </div>
                </div>
                <div class="form-group">
                  <label data-translate="" class="col-md-4 control-label">owner</label>
                  <div class="col-md-8">
                    <select class="form-control" id="gn-batchSearchOwner"
                            data-ng-model="searchObj.params._owner">
                      <option></option>
                      <option data-ng-repeat="u in batchSearchUsers | orderBy: 'username'"
                              value="{{u.id}}">{{u.name}} {{u.surname}} ({{u.username}})
                      </option>
                    </select>
                  </div>
                </div>
                <div class="form-group">
                  <label data-translate="" class="col-md-4 control-label">_cat</label>
                  <div class="col-md-8">
                    <select class="form-control" id="gn-batchSearchCategory"
                            data-ng-model="searchObj.params._cat">
                      <option></option>
                      <option data-ng-repeat="c in batchSearchCategories" value="{{c.name}}"
                      >{{c.label[lang]}}
                      </option>
                    </select>
                  </div>
                </div>
              </fieldset>
            </div>
          </div>


          <div class="row"
               data-ng-show="searchResults.records.length > 0">
            <div class="col-md-4 relative">
              <div data-gn-selection-widget=""
                   data-without-action-menu=""
                   data-results="searchResults"></div>
            </div>
            <div class="col-md-8">
              <div class="pull-right"
                   data-gn-pagination="paginationInfo"
                   data-hits-values="searchObj.hitsperpageValues"></div>
            </div>
          </div>

          <div class="row">
            <div class="col-md-12">
             <span class="loading fa fa-spinner fa-spin"
                   data-ng-show="searching"></span>

              <div class="alert alert-warning" role="alert"
                   ng-if="!searching && searchResults.count == 0">
                <i class="fa fa-frown-o"></i>
                <span data-translate="">zarooResult</span>
              </div>

              <div data-ng-show="searchResults.records.length > 0"
                   data-gn-results-container=""
                   data-search-results="searchResults"
                   data-template-url="resultTemplate"></div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>


  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading" data-translate="">configureProcess</div>
      <div class="panel-body">
        <form class="form-horizontal" id="gn-batch-process">
              <input type="hidden" name="_csrf" value="{{csrf}}"/>
          <select class="form-control"
                  data-ng-disabled="selection.length == 0"
                  data-ng-model="data.selectedProcess"
                  data-ng-options="p as (p.key | translate) for p in batchProcesses">
          </select>
          <!-- ng-options set only a index for the select value,
          bound the process name in a hidden field -->
          <input type="hidden" name="process" value="{{data.selectedProcess.key}}"/>
          <fieldset data-ng-hide="!selectedProcess">
            <legend data-translate=""
                    data-ng-hide="selectedProcess.params.length == 0">batchProcessParameters
            </legend>

            <div data-ng-switch="selectedProcess.type">
              <div data-ng-switch-when="fixed-params">
                <div data-ng-repeat="p in selectedProcess.params track by $index" data-ng-switch=""
                     data-on="p.type" class="form-group">
                  <label for="batch_param_{{p.name}}" class="col-md-4 control-label">{{p.name |
                    translate}}</label>
                  <div class="col-md-8">
                    <textarea data-ng-switch-when="textarea" class="form-control"
                              id="batch_param_{{p.name}}" name="{{p.name}}">{{p.value}}</textarea>
                    <input data-ng-switch-default="" id="batch_param_{{p.name}}" name="{{p.name}}"
                           type="{{p.type || 'text'}}" class="form-control"
                           placeholder="{{p.value}}"/>

                    <p class="help-block"
                       data-ng-show="((p.name + '-help') | translate) != (p.name + '-help')"
                       data-translate="">{{(p.name + '-help')}}</p>
                  </div>
                </div>

                <div class="btn-toolbar" data-ng-show="selectedProcess.type != 'template'">
                  <button type="button" class="btn btn-primary btn-lg pull-right"
                          data-ng-disabled="!selectedProcess"
                          data-ng-click="runProcess('#gn-batch-process')">
                    <i class="fa fa-play"></i>&nbsp;
                    <span data-translate="">runProcess</span>
                  </button>
                </div>
              </div>

              <div data-ng-switch-when="template">
                <div data-ng-include="selectedProcess.template">
                </div>
              </div><!-- end ng-switch-when-->

              <div data-ng-switch-default class="alert alert-danger"
                   data-translate="batchProcessTypeUnsupported"
                   data-translate-values="{type: selectedProcess.type}">
              </div><!-- end ng-switch-default -->

            </div><!-- end ng-switch -->
          </fieldset>

        </form>
      </div>
    </div>
  </div>

  <!-- Report -->
  <div id="gn-batch-process-report" data-ng-switch="selectedProcess.type">
    <div class="col-md-12"
         data-ng-hide="!processing && !processReport" data-ng-switch-when="fixed-params">

      <div data-ng-show="processing">
        <i class="fa fa-spinner fa-spin"/>
      </div>

      <div data-gn-batch-report="processReport"/>
    </div>

    <div data-ng-switch-when="template">
      <div data-ng-include="selectedProcess.reportTemplate">
      </div>
    </div>
  </div>

  <div data-gn-need-help="user-guide/workflow/batchupdate.html"></div>
</div>
